"use client"; import { ColumnDef } from "@tanstack/react-table"; import { Badge } from "@/components/ui/badge"; import { TestProduct } from "@/db/schema/test-table-v2"; import { OrderWithDetails } from "./column-defs"; // === Product Columns (Pattern 1, 2) === // meta.serverGroupable: 서버 사이드 GROUP BY 지원 여부 export const productColumns: ColumnDef[] = [ { accessorKey: "id", header: "ID", size: 60, enableGrouping: false, // 클라이언트 그룹핑도 비활성화 meta: { serverGroupable: false }, }, { accessorKey: "sku", header: "SKU", size: 100, enableGrouping: false, meta: { serverGroupable: false }, }, { accessorKey: "name", header: "Product Name", size: 200, enableGrouping: false, meta: { serverGroupable: false }, }, { accessorKey: "category", header: "Category", size: 120, enableGrouping: true, // ✅ 그룹핑 가능 meta: { serverGroupable: true }, cell: ({ getValue }) => { const category = getValue() as string; return {category}; }, }, { accessorKey: "price", header: "Price", size: 100, enableGrouping: false, meta: { serverGroupable: false }, cell: ({ getValue }) => { const price = parseFloat(getValue() as string); return new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", }).format(price); }, }, { accessorKey: "stock", header: "Stock", size: 80, enableGrouping: false, meta: { serverGroupable: false }, cell: ({ getValue }) => { const stock = getValue() as number; return ( {stock} ); }, }, { accessorKey: "status", header: "Status", size: 110, enableGrouping: true, // ✅ 그룹핑 가능 meta: { serverGroupable: true }, cell: ({ getValue }) => { const status = getValue() as string; const variants: Record = { active: "default", inactive: "secondary", discontinued: "destructive", }; return {status}; }, }, { accessorKey: "isNew", header: "New", size: 60, enableGrouping: true, // ✅ 그룹핑 가능 meta: { serverGroupable: true }, cell: ({ getValue }) => { const isNew = getValue() as boolean; return isNew ? NEW : null; }, }, { accessorKey: "createdAt", header: "Created", size: 110, enableGrouping: false, meta: { serverGroupable: false }, cell: ({ getValue }) => { const date = getValue() as Date; return date ? new Date(date).toLocaleDateString() : "-"; }, }, ]; // === Order Columns with joined data (Pattern 3 - Custom Service) === export const orderColumns: ColumnDef[] = [ { accessorKey: "id", header: "ID", size: 60, }, { accessorKey: "orderNumber", header: "Order #", size: 140, cell: ({ getValue }) => ( {getValue() as string} ), }, { accessorKey: "customerName", header: "Customer", size: 150, }, { accessorKey: "customerTier", header: "Tier", size: 90, cell: ({ getValue }) => { const tier = getValue() as string; if (!tier) return "-"; const colors: Record = { standard: "bg-gray-500", premium: "bg-blue-500", vip: "bg-amber-500", }; return ( {tier.toUpperCase()} ); }, }, { accessorKey: "productName", header: "Product", size: 180, }, { accessorKey: "quantity", header: "Qty", size: 60, }, { accessorKey: "totalAmount", header: "Total", size: 100, cell: ({ getValue }) => { const amount = parseFloat(getValue() as string); return new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", }).format(amount); }, }, { accessorKey: "status", header: "Status", size: 110, cell: ({ getValue }) => { const status = getValue() as string; const variants: Record = { pending: "outline", processing: "secondary", shipped: "default", delivered: "default", cancelled: "destructive", }; const colors: Record = { delivered: "bg-emerald-500", shipped: "bg-blue-500", }; return ( {status} ); }, }, { accessorKey: "orderedAt", header: "Order Date", size: 110, cell: ({ getValue }) => { const date = getValue() as Date; return date ? new Date(date).toLocaleDateString() : "-"; }, }, ];